package com.neu.tlias.controller;


import com.neu.tlias.pojo.Dept;
import com.neu.tlias.pojo.Emp;
import com.neu.tlias.pojo.Result;
import com.neu.tlias.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-22
 */
@Api(tags = "部门管理接口")
@Slf4j
@RestController
@RequestMapping("/depts")
@RequiredArgsConstructor
public class DeptController {

    private final IDeptService deptService;

    @ApiOperation("查询部门接口")
    @GetMapping
    public Result list(){
        log.info("查询全部部门数据");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }
    @ApiOperation("新增部门接口")
    @PostMapping
    public Result save(@RequestBody Dept dept){
        log.info("新增部门:{}",dept);
        deptService.save(dept);
        return Result.success();
    }


    @ApiOperation("删除部门接口")
    @DeleteMapping("/{id}")
    public Result delete(@ApiParam("用户id") @PathVariable("id") Long id){
        log.info("根据id删除部门：{}",id);
        deptService.removeById(id);
        return Result.success();
    }

    @ApiOperation("根据id查询部门接口")
    @GetMapping("{id}")
    public Result getById(@ApiParam("用户id") @PathVariable("id") Long id){
        Dept dept = deptService.getById(id);
        return Result.success(dept);
    }

    @ApiOperation("根据id修改员工接口")
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改员工:{}",dept);
        deptService.updateById(dept);
        return Result.success();
    }

}
